package com.pdsu.graduation_design.views;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioButton;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.adapter.M_FragmentPagerAdapter;
import com.pdsu.graduation_design.listener.Bottom_Tap_OnClickListener;
import com.pdsu.graduation_design.listener.My_Like_RB_OnClickListener;

import java.util.ArrayList;
import java.util.List;

public class My_Like_Activity extends AppCompatActivity {


    private ViewPager my_like_viewpage;
    private List<Fragment> fragmentList;
    private My_Like_RB_OnClickListener bottom_tap_onClickListener;
    private RadioButton like_co_btn,like_st_btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_like);
        init();
        bind();
    }
    void init(){
        my_like_viewpage=findViewById(R.id.my_like_viewpage);
        fragmentList=new ArrayList<>();
        like_co_btn=findViewById(R.id.my_like_co_btn);
        like_st_btn=findViewById(R.id.my_like_st_btn);

    }
    void bind(){

        fragmentList.add(new My_Like_Commodity_Fragment());
        fragmentList.add(new My_Like_Store_Fragment());
        my_like_viewpage.setAdapter(new M_FragmentPagerAdapter(getSupportFragmentManager(),fragmentList));

        bottom_tap_onClickListener=new My_Like_RB_OnClickListener(my_like_viewpage);

        like_co_btn.setOnClickListener(bottom_tap_onClickListener);
        like_st_btn.setOnClickListener(bottom_tap_onClickListener);
        my_like_viewpage.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

                if (state==2){

                    int currentItemPosition = my_like_viewpage.getCurrentItem();

                    switch (currentItemPosition){
                        case 0:
                            like_co_btn.setChecked(true);
                            break;
                        case 1:
                            like_st_btn.setChecked(true);
                            break;

                    }

                }
            }


        });

    }
}